package com.entmanage.base.hrm.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.entmanage.common.annotation.Log;
import com.entmanage.common.core.controller.BaseController;
import com.entmanage.common.core.domain.AjaxResult;
import com.entmanage.common.enums.BusinessType;
import com.entmanage.base.hrm.domain.HrmEmployeeCertificate;
import com.entmanage.base.hrm.service.IHrmEmployeeCertificateService;
import com.entmanage.common.utils.poi.ExcelUtil;
import com.entmanage.common.core.page.TableDataInfo;

/**
 * 员工证书子Controller
 *
 * @author lsq
 * @date 2025-09-02
 */
@Api(tags = {"hrm-HrmEmployeeCertificate模块"}, description = "员工证书子")
@RestController
@RequestMapping("/hrm/certificate")
public class HrmEmployeeCertificateController extends BaseController
{
    @Autowired
    private IHrmEmployeeCertificateService hrmEmployeeCertificateService;

    /**
     * 查询员工证书子列表
     */
    @PreAuthorize("@ss.hasPermi('hrm:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(HrmEmployeeCertificate hrmEmployeeCertificate)
    {
        startPage();
        List<HrmEmployeeCertificate> list = hrmEmployeeCertificateService.selectHrmEmployeeCertificateList(hrmEmployeeCertificate);
        return getDataTable(list);
    }

    /**
     * 导出员工证书子列表
     */
    @PreAuthorize("@ss.hasPermi('hrm:certificate:export')")
    @Log(title = "员工证书子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HrmEmployeeCertificate hrmEmployeeCertificate)
    {
        List<HrmEmployeeCertificate> list = hrmEmployeeCertificateService.selectHrmEmployeeCertificateList(hrmEmployeeCertificate);
        ExcelUtil<HrmEmployeeCertificate> util = new ExcelUtil<HrmEmployeeCertificate>(HrmEmployeeCertificate.class);
        util.exportExcel(response, list, "员工证书子数据");
    }

    /**
     * 获取员工证书子详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrm:certificate:query')")
    @GetMapping(value = "/{certId}")
    public AjaxResult getInfo(@PathVariable("certId") Long certId)
    {
        return success(hrmEmployeeCertificateService.selectHrmEmployeeCertificateByCertId(certId));
    }

    /**
     * 新增员工证书子
     */
    @PreAuthorize("@ss.hasPermi('hrm:certificate:add')")
    @Log(title = "员工证书子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HrmEmployeeCertificate hrmEmployeeCertificate)
    {
        return toAjax(hrmEmployeeCertificateService.insertHrmEmployeeCertificate(hrmEmployeeCertificate));
    }

    /**
     * 修改员工证书子
     */
    @PreAuthorize("@ss.hasPermi('hrm:certificate:edit')")
    @Log(title = "员工证书子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HrmEmployeeCertificate hrmEmployeeCertificate)
    {
        return toAjax(hrmEmployeeCertificateService.updateHrmEmployeeCertificate(hrmEmployeeCertificate));
    }

    /**
     * 删除员工证书子
     */
    @PreAuthorize("@ss.hasPermi('hrm:certificate:remove')")
    @Log(title = "员工证书子", businessType = BusinessType.DELETE)
    @DeleteMapping("/{certIds}")
    public AjaxResult remove(@PathVariable Long[] certIds)
    {
        return toAjax(hrmEmployeeCertificateService.deleteHrmEmployeeCertificateByCertIds(certIds));
    }

    /**
     * 根据员工ID查询证书列表
     */
    @GetMapping("/listByEmpId/{empId}")
    public AjaxResult listByEmpId(@PathVariable Long empId) {
        List<HrmEmployeeCertificate> list = hrmEmployeeCertificateService.selectCertificateByEmpId(empId);
        return AjaxResult.success(list);
    }
}
